

#ifndef TV_STB_IMAGE_SOURCE_H
#define TV_STB_IMAGE_SOURCE_H

#include <memory>

#include "display_options.h"
#include "image_source.h"

namespace tv {
// STB image loader fallback. Not pretty and should only be used as fallback.
class STBImageSource final : public ImageSource {
public:
  explicit STBImageSource(const std::string &filename);
  ~STBImageSource() final;

  // Attempt to load given filename as video, open stream and set-up scaling.
  // Returns true on success.
  bool LoadAndScale(const DisplayOptions &options, int frame_offset,
                    int frame_count) final;

  // Play video up to given duration.
  //
  // The reference to the "interrupt_received" can be updated by a signal
  // while the method is running and shall be checked often.
  void SendFrames(const Duration &duration, int loops,
                  const volatile sig_atomic_t &interrupt_received,
                  const Renderer::WriteFramebufferFun &sink) final;

  std::string FormatTitle(const std::string &format_string) const final;

private:
  class PreprocessedFrame;
  std::vector<PreprocessedFrame *> frames_;
  int orig_width_, orig_height_;
  int max_frames_ = 1;
  int indentation_ = 0;
};
} // namespace tv

#endif // TV_STB_IMAGE_SOURCE_H
